package IOPeration;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Deletebook implements Ioperation {
    public void work(BookList bookList){
        System.out.println("删除图书");
        Scanner scanner=new Scanner(System.in);
        System.out.println("请你输入你要删除图书的名字");
        String name=scanner.nextLine();
        int pos=-1;
        int i=0;
        int currenTsize= bookList.getUsedsize();
        for(;i<currenTsize;i++){
            Book book=bookList.getBooks(i);
            if(book.getName().equals(name)){
                pos=i;
                break;
            }
        }
   if(i==currenTsize){
      System.out.println("没有你要删除的书");
      return;
}
for(int j=pos;j<currenTsize-1;j++){
    Book book = bookList.getBooks(j+1);
    bookList.setBooks(j,book);

}
bookList.setBooks(currenTsize-1,null);
bookList.setUsedsize(currenTsize-1);
System.out.println("删除成功");



    }

}
